package com.letv.so.service.impl;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import net.rubyeye.xmemcached.MemcachedClient;


import com.letv.so.service.CacheService;

public class XMemcachedServiceImpl<T> implements CacheService<T> {

    private MemcachedClient memcachedClient;

    public T get(String key) {
        try {
            return memcachedClient.get(key);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public Map<String, T> getMulti(Collection<String> keys) {
        try {
            return memcachedClient.get(keys);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public Map<String, T> getMulti(String[] keys) {

        return getMulti(Arrays.asList(keys));
    }

    public void setMemcachedClient(MemcachedClient memcachedClient) {
        this.memcachedClient = memcachedClient;
    }

}
